package com.ruoyi.common.python;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

@Component
public class PythonScriptExecute {

    private static final Logger log = LoggerFactory.getLogger(PythonScriptExecute.class);

    public boolean execute(String scriptPath, String scriptName) {
        try {
            ProcessBuilder processBuilder = new ProcessBuilder("python", scriptPath + scriptName);
            // 启动进程
            Process process = processBuilder.start();
            // 等待脚本执行完成
            int exitCode = process.waitFor();
            if(exitCode==1){
                return true;
            }
        } catch (Exception e) {
            log.error("python 脚本执行失败", e);
        }
        return false;
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        String pythonScript = "C:\\Users\\Administrator\\PycharmProjects\\AutoPage\\";

        String pythonFile = "stock.py";


    }
}
